home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / gofer221.zip / APPX_D < prev    next >
Text File  |  1991-11-20  |  4KB  |  133 lines

  1.  
  2.  
  3. Introduction to Gofer         APPENDIX D: USING GOFER WITH BIRD+WADLER          
  4.  
  5.  
  6. APPENDIX D: USING GOFER WITH BIRD+WADLER
  7.  
  8. Bird and Wadler's textbook  [1]  gives  an  excellent  introduction  to
  9. functional programming, providing an insight into both basic techniques
  10. and matters of programming style as well as describing  the  underlying
  11. mathematics and its use for program development and  derivation.   Most
  12. of the programs in that book can be used with Gofer although there  are
  13. a number of differences between the two notations.  Fortunately, it  is
  14. not difficult to  translate  from  one  notation  to  the  other.   The
  15. following points are particularly useful for this:
  16.  
  17.   o  Type constructors in Gofer  begin with capital letters (e.g. Bool,
  18.      Char etc..) where lower case is used in  [1]  (e.g.   bool,  char,
  19.      etc..).  Note that Gofer has no general numeric type "num" as used
  20.      in [1];  Use  either  Int,  Float,  or  overloading  in  Gofer  as
  21.      appropriate.
  22.  
  23.   o  Datatype definitions in [1] are written in the form lhs::=constrs.
  24.      The equivalent definition in Gofer is: data lhs = constrs.
  25.  
  26.      Similarly, a type synonym definition in [1] of the form lhs == rhs
  27.      can be written in Gofer as: type lhs = rhs.
  28.  
  29.   o  The differences between the syntax used for  guarded equations  in
  30.      Gofer compared with the notation used in  [1]  have  already  been
  31.      discussed in section 9.2.  For example:
  32.  
  33.      Using the notation of [1]:       Using Gofer:
  34.  
  35.      filter p (x:xs)                  filter p (x:xs)
  36.        = x : filter p xs, if p x         | p x       = x : filter p xs
  37.        = filter p xs,     otherwise      | otherwise = filter p xs
  38.  
  39.   o  In Gofer,  list comprehension qualifiers  are separated by  commas
  40.      rather than semicolons as used in [1].
  41.  
  42.   o  A number of the  function names and types in the  standard prelude
  43.      are different:
  44.  
  45.              [1]         Gofer            [1]         Gofer
  46.              ---         -----            ---         ----
  47.              (#)         length           takewhile   takeWhile
  48.              (~)         not              dropwhile   dropWhile
  49.              (/\)        (&&)             zipwith     zipWith
  50.              (\/)        (||)             swap        flip
  51.              (!)         (!!)             in          elem
  52.              (--)        (\\)             scan        scanl
  53.              hd          head             some        any
  54.              tl          tail             listmin     minimum
  55.              decode      chr              listmax     maximum
  56.              code        ord
  57.  
  58.      See appendix B for a complete list of standard functions in Gofer.
  59.  
  60.      The version of foldl  using  "strict"  which  appears  in  [1]  is
  61.      available in Gofer as the function "foldl'".
  62.  
  63.  
  64.                                       115
  65.  
  66.  
  67.  
  68.  
  69. Introduction to Gofer         APPENDIX D: USING GOFER WITH BIRD+WADLER          
  70.  
  71.  
  72.      The role of "zip" and "zipwith" in [1] is filled by the "zip"  and
  73.      "zipWith" families of functions in Gofer.  An  expression  of  the
  74.      form "zip (xs,ys)" in [1] is equivalent to "zip xs  ys"  in  Gofer
  75.      etc...
  76.  
  77.   o  Gofer does not enforce the condition assumed in [1] that the  left
  78.      hand sides of each of the equations defining a  function  must  be
  79.      disjoint.
  80.  
  81.   o  The equality operator in Gofer is written as  "=="  and the single
  82.      equality character "=" is a reserved symbol used to separate  left
  83.      and right hand sides of equations.  Many  C  programmers  will  be
  84.      familiar with this kind of notation (together with  the  kinds  of
  85.      problems it can create!).
  86.  
  87.   o  Some of the  identifiers used in  [1] are reserved words in Gofer.
  88.      Examples that are particularly likely to occur  include  "in"  and
  89.      "then".
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                       116
  131.  
  132.  
  133.